package logic

import (
	"context"
	"day15/model/mysql"
	"day15/rpc/internal/svc"
	"day15/rpc/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLoginLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLoginLogic {
	return &UserLoginLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserLoginLogic) UserLogin(in *pb.UserLoginReq) (*pb.UserLoginResp, error) {
	userModel := mysql.User{}
	user, err := userModel.Login(in.Username, in.Password)
	if err != nil {
		return nil, err
	}
	return &pb.UserLoginResp{
		Id:       int64(user.ID),
		Username: user.Username,
		Phone:    user.Phone,
		Email:    user.Email,
		IdCard:   user.IdCard,
		Avatar:   user.Avatar,
	}, nil
}
